package com.enation.app.shop.front.policyInsurance.adminController;

import com.enation.app.shop.front.policyInsurance.entity.ClaimApplication;
import com.enation.app.shop.front.policyInsurance.entity.Supplier;
import com.enation.app.shop.front.policyInsurance.layuiGrid.LayuiResponse;
import com.enation.app.shop.front.policyInsurance.layuiGrid.LayuiUtil;
import com.enation.app.shop.front.policyInsurance.service.ClaimApplicationMapper;
import com.enation.app.shop.front.policyInsurance.service.ISupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * web后台供应商
 */
@Scope("prototype")
@Controller
@RequestMapping("/web/supplier")
public class SupplierController {
    @Autowired
    private ISupplierMapper supplierMapper;

    @Autowired
    private ClaimApplicationMapper  claimApplicationMapper;

    /**
     *创建供应商
     */
    @ResponseBody
    @RequestMapping("/add")
    public Boolean create(String suppliername,
                          String suppliermobile,
                          String supplierpassword,
                          String supplierdetail,
                          Integer status,
                          String supplieruser,
                          String suppliertel,
                          String suppliercard,
                          String supplieraddress,
                          String bussiness_scope,
                          String pic){
        Supplier supplier=new Supplier();
        supplier.setSupplier_name(suppliername);
        supplier.setMobile(suppliermobile);
        supplier.setPassword(supplierpassword);
        supplier.setDetail(supplierdetail);
        supplier.setStatus(status);
        supplier.setSupplier_user(supplieruser);
        supplier.setSupplier_tel(suppliertel);
        supplier.setSupplier_card(suppliercard);
        supplier.setSupplier_address(supplieraddress);
        supplier.setBussiness_scope(bussiness_scope);
        supplier.setLogo(pic);
        int i= supplierMapper.insert(supplier);
        if (i>0){
            return true;
        }else {
            return false;
        }
    }




    /**
     *web得到所有供应商接口
     */
    @ResponseBody
    @RequestMapping("/getsupplierlist")
    public LayuiUtil getAllTemplatetest(Integer page, Integer limit, String seacher){
        if (seacher==null){
            List<Supplier> Suppliers=supplierMapper.getAll();
            List<Supplier> SupplierList= supplierMapper.getByPage((page-1)*limit,limit,seacher);
            return LayuiResponse.getObjectMessageJson(SupplierList,"ss",Suppliers.size());
        }else {
            List<Supplier> Suppliers=supplierMapper.getBySercher(seacher);
            List<Supplier> SupplierList= supplierMapper.getByPage((page-1)*limit,limit,seacher);
            return LayuiResponse.getObjectMessageJson(SupplierList,"ss",Suppliers.size());
        }

    }

    /**
     *web得到所有供应商接口
     */
    @ResponseBody
    @RequestMapping("/getClaimList")
    public LayuiUtil getClaimList(Integer page1, Integer limit1, String seacher){
        if (seacher==null){
            List<ClaimApplication> claimApplications=claimApplicationMapper.getAll();
            List<ClaimApplication> claimApplicationList=claimApplicationMapper.getByPage((page1-1)*limit1,limit1,seacher);
            return LayuiResponse.getObjectMessageJson(claimApplicationList,"ss",claimApplications.size());
        }else {
            List<ClaimApplication> claimApplications=claimApplicationMapper.getBySercher(seacher);
            List<ClaimApplication> claimApplicationList= claimApplicationMapper.getByPage((page1-1)*limit1,limit1,seacher);
            return LayuiResponse.getObjectMessageJson(claimApplicationList,"ss",claimApplications.size());
        }
    }
















}
